package listbyorder.access101_200.test199;

import listbyorder.utils.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/15 14:27
 */
public class Solution1 {

    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if (root != null) {
            Queue<TreeNode> queue = new LinkedList<>();
            queue.add(root);
            TreeNode temp = null;
            while (!queue.isEmpty()) {
                int len = queue.size();
                while (len != 0) {
                    temp = queue.poll();
                    if (temp.left != null) {
                        queue.add(temp.left);
                    }
                    if (temp.right != null) {
                        queue.add(temp.right);
                    }
                    len--;
                }
                res.add(temp.val);
            }
        }
        return res;
    }
}
